<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('月评价分公司审核列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">任务年月</label>
                <div class="layui-input-inline">
                    <input type="text" name="taskMonth" placeholder="" class="layui-input" id="taskMonth">
                </div>
                <label class="layui-form-label">任务状态</label>
                <div class="layui-input-inline">
                    <select name="taskState" lay-filter="aihao">
                        <option value=""></option>
                        <option value="0">未填报</option>
                        <option value="1">待审核</option>
                        <option value="2">驳回调整中</option>
                        <option value="3">分公司审核完成</option>
                    </select>
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
                        lay-filter="monthSubAudit-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="monthSubAudit-table" lay-filter="monthSubAudit-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="monthSubAudit-toolbar">
<!--    <button shiro:hasPermission="gen:monthSubAudit:add" class="pear-btn pear-btn-primary pear-btn-md"-->
<!--            lay-event="add">-->
<!--        <i class="layui-icon layui-icon-add-1"></i>-->
<!--        新增-->
<!--    </button>-->
<!--    <button shiro:hasPermission="gen:monthSubAudit:remove" class="pear-btn pear-btn-danger pear-btn-md"-->
<!--            lay-event="batchRemove">-->
<!--        <i class="layui-icon layui-icon-delete"></i>-->
<!--        删除-->
<!--    </button>-->
    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="allcommit">
        月度数据一键提报
    </button>
</script>

<script type="text/html" id="monthSubAudit-bar">
    <button  class="pear-btn pear-btn-primary pear-btn-sm"
             lay-event="audit" title="供电所上报结果审阅"><i class="layui-icon layui-icon-survey"></i>
        供电所上报结果审阅
    </button>
    <button  class="pear-btn pear-btn-primary pear-btn-sm"
             lay-event="viewResult" title="查看已提报结果"><i class="layui-icon layui-icon-form"></i>
        查看已提报结果
    </button>
    <button  class="pear-btn pear-btn-danger pear-btn-sm"
             lay-event="reject" title="驳回"><i class="layui-icon layui-icon-prev-circle"></i>
        驳回
    </button>
<!--    <button shiro:hasPermission="gen:monthSubAudit:edit" class="pear-btn pear-btn-primary pear-btn-sm"-->
<!--            lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>-->
<!--    </button>-->

<!--    <button shiro:hasPermission="gen:monthSubAudit:remove" class="pear-btn pear-btn-danger pear-btn-sm"-->
<!--            lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>-->
<!--    </button>-->
</script>


<script type="text/html" id="monthSubAudit-type">
    {{#if (d.dataState == '0') { }}
    <span class="layui-badge layui-bg-orange">开启</span>
    {{# }else if(d.dataState == '-1'){ }}
    <span class="layui-badge layui-bg-blue">关闭</span>
    {{# } }}
</script>

<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        //默认查上个月数据
        var year = new Date().getFullYear()
        var month = new Date().getMonth();
        month = (month < 10 ? "0" + month : month);
        if (month == '00'){
            month = 12
            year = year - 1
        }
        //执行一个laydate实例
        laydate.render({
            elem: '#taskMonth' //指定元素
            ,type: 'month'
            // ,value: new Date()
            ,value: year + "-" + month
        })

        var MODULE_PATH = rootPath + "/MonthSubAuditController/";
        var cols = [
            [
                // {type: 'checkbox'},

                {title: '任务年月', field: 'taskMonth', align: 'center',width:'10%'},

                {title: '供电所名称', field: 'supplyName', align: 'center',width:'15%'},

                {
                    field: 'taskState', title: '填报任务状态', align: 'center',width:'10%', templet: function (res) {
                        if (res.taskState == '0') {
                            return '未填报';
                        } else if (res.taskState == '1') {
                            return '待审核';
                        } else if (res.taskState == '2') {
                            return '驳回调整中';
                        } else if (res.taskState == '6') {
                            return '驳回调整重新提报';
                        } else {
                            return '分公司审核完成'
                        }
                    }
                },

                {title: '供电所上报时间', field: 'commitDate', align: 'center',width:'15%'},

                {title: '审核完成时间', field: 'auditDate', align: 'center',width:'15%'},

                // {title: '审核截止时间', field: 'auditStopLineDate', align: 'center'},//后期优化

                {title: '操作', toolbar: '#monthSubAudit-bar', align: 'center',width:'35%'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#monthSubAudit-table',
            url: MODULE_PATH + 'list',
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#monthSubAudit-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }],
            where: {'taskMonth': year + "-" + month}
        });

        //table图标事件绑定
        table.on('tool(monthSubAudit-table)', function (obj) {
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else if (obj.event === 'audit') {
                window.audit(obj);
            } else if (obj.event === 'reject') {
                window.reject(obj);
            } else if (obj.event === 'viewResult') {
                window.viewResult(obj);
            }
        });

        //table工具栏绑定
        table.on('toolbar(monthSubAudit-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            } else if (obj.event === 'allcommit') {
                window.allcommit(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(monthSubAudit-query)', function (data) {
            table.reload('monthSubAudit-table', {where: data.field})
            return false;
        });


        //添加
        window.add = function () {
            layer.open({
                type: 2,
                title: '新增',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'add'
            });
        }
        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
        }
        //删除
        window.remove = function (obj) {
            layer.confirm('确定要删除该数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        //批量删除
        window.batchRemove = function (obj) {
            var data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            var ids = "";
            for (var i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些数据', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove?ids=" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('monthSubAudit-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }
        //审核
        window.audit = function (obj) {
            if (obj.data['taskState']!='1'){
                layer.msg("当前状态不可审阅", {icon: 2, time: 1000});
            }else {
                var index = layer.open({
                    type: 2,
                    title: obj.data['taskMonth']+'--'+obj.data['supplyName']+'---分公司审核',
                    shade: 0.1,
                    // area: ['100%', '100%'],
                    content: MODULE_PATH + 'audit/'+ obj.data['id']
                });
                layer.full(index);
            }
        }

        //驳回
        window.reject = function (obj) {
            if (obj.data['taskState']!='1'){
                layer.msg("当前状态下不可驳回", {icon: 2, time: 1000});
            }else {
                layer.open({
                    type: 2,
                    title: obj.data['taskMonth']+'--'+obj.data['supplyName']+'---驳回调整',
                    shade: 0.1,
                    area: ['500px', '300px'],
                    content: MODULE_PATH + 'reject/'+ obj.data['id']
                });
            }
        }

        //查看填报结果
        window.viewResult = function (obj) {
            if (obj.data['taskState'] =='0'||obj.data['taskState'] =='1'||obj.data['taskState'] =='2'){
                layer.msg("当前状态单据不允许查看", {icon: 2, time: 1000});
            }else {
                var index = layer.open({
                    type: 2,
                    title: '查看上报结果--'+obj.data['taskMonth']+'--'+obj.data['supplyName'],
                    shade: 0.1,
                    // area: ['100%', '100%'],
                    content: MODULE_PATH + 'viewResult/'+ obj.data['id']
                });
                layer.full(index);
            }
        }

        //刷新按钮
        window.refresh = function () {
            table.reload('monthSubAudit-table');
        }

        //一键提报
        window.allcommit = function (obj) {
            var taskMonth = obj.config.where.taskMonth;
            layer.confirm('提报后无法撤销，确定将年月为'+taskMonth+'对应的剩余未提报数据进行一键提报么？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                var loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "allCommit",
                    data: JSON.stringify({"taskMonth": taskMonth}),
                    contentType: 'application/json',
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.code == 200) {
                            layer.msg(result.msg, {icon: 1, time: 3000}, function () {
                                table.reload('monthSubAudit-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 3000}, function () {
                                table.reload('monthSubAudit-table');
                            });
                        }
                    }
                })
            });
        }
    })
</script>
</html>